-- 衍生 问计
local ref_wenji = fk.CreateSkill {
    name = "mcdh_ref_wenji",
}

ref_wenji:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play and
                not table.every(player.room:getOtherPlayers(player), function(p) return (p:isNude()) end)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player), function(p)
            return not p:isNude() end), Util.IdMapper), 1, 1, "#mcdh_ref_wenji-choose", self.name, true)
        if #to > 0 then
            self.cost_data = to[1]
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        local card = room:askForCard(to, 1, 1, true, self.name, false, ".", "#mcdh_ref_wenji-give::"..player.id)
        room:setPlayerMark(player, "mcdh_ref_wenji-turn", Fk:getCardById(card[1]).trueName)
        room:obtainCard(player.id, card[1], false, fk.ReasonGive)
    end,
})

ref_wenji:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:getMark("mcdh_ref_wenji-turn") ~= 0 and player:getMark("mcdh_ref_wenji-turn") == data.card.trueName
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        data.disresponsiveList = data.disresponsiveList or {}
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            table.insertIfNeed(data.disresponsiveList, p.id)
        end
    end,
})


return ref_wenji